package utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by charmyyy on 2017/11/30.
 */
public class SessionUtils {
    //向session中添加对象
    public static void add(HttpServletRequest request, String key, Object value){
        HttpSession session = request.getSession();
        session.setAttribute(key,value);
        session.setMaxInactiveInterval(-1);
    }
    //session对象中移除
    public static void rmv(HttpServletRequest request,String name){
        HttpSession session = request.getSession();
        session.removeAttribute(name);
    }
    //session对象中获取
    public static Object get(HttpServletRequest req, String name) {
        HttpSession session = req.getSession();
        return session.getAttribute(name);
    }
}
